﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CentaLine.DAL;
using CentaLine.Model;

namespace CentaLine.Repository
{
    /// <summary>
    /// 业务员操作相类
    /// </summary>
    public class CounselorManager
    {
        //此处可用依赖注入
         CounselorDAL counselorDAL = null;
         VitualPhoneDAL vitualPhoneDAL = null;
        public CounselorManager()
        {
            if (counselorDAL == null)
                counselorDAL = new CounselorDAL();
            if (vitualPhoneDAL == null)
                vitualPhoneDAL = new VitualPhoneDAL();
        }

        ///// <summary>
        ///// 根据业务员信息获取其上级总监的信息
        ///// </summary>
        ///// <param name="CounselorId">业务员工号</param>
        ///// <returns></returns>
        //public Director GetDirectorInfoByCounselor(string counselorId)
        //{
        //    Director d = counselorDAL.GetDirectorInfoByCounselorDAL(counselorId);
        //    return d;
        //}

        /// <summary>
        /// 返回业务员信息，包含其对于的总监信息
        /// </summary>
        /// <param name="counselorId"></param>
        /// <returns></returns>
        public　Counselor GetCounselor(string counselorId)
        {
            return counselorDAL.GetCounselorDAL(counselorId);
        }
        /// <summary>
        /// 根据手机号获取业务信息
        /// </summary>
        /// <param name="mobile"></param>
        /// <returns></returns>
        public Counselor GetCounrsorByMobile(string mobile)
        {
            var applist = vitualPhoneDAL.GetAllCounselorApplicationListDAL(DateTime.Now,null,null,null,mobile).ToList();
            if (applist.Any())
            {
                var appUnit = applist[0];
                if (appUnit != null)
                {
                    var counselor = GetCounselor(appUnit.CounselorId);
                    return counselor;
                }
            }
            return null;
        }
    }


}
